package com.example.demo.javatest.thread.pool;

import java.util.Objects;
import java.util.concurrent.*;

/**
 * Created by ljh on 2019/5/12.
 */
public class ThreadPool {
    public static void main(String[] args) {
        ExecutorService pools= Executors.newFixedThreadPool(10);
        for (int i = 0; i < 20 ;i++) {
            int finalI = i;
            pools.execute(()->{
                System.out.printf("第 %s 个 进入 %n", finalI);
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(finalI+"end");
            });

        }

    }

    public static  void  fun1(){
        ExecutorService pools= Executors.newFixedThreadPool(10);
        pools.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"A开始");
            }
        });
        Future<Object> future= pools.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                System.out.println("sdadas");
                return "hahah";
            }
        });
        try {
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        pools.shutdown();
    }
}
